package org.ohuyo.libra.server.dao.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.ohuyo.commons.query.HibernateDaoSupportEx;
import org.ohuyo.libra.server.dao.JumpTicketDao;
import org.ohuyo.libra.server.model.table.JumpTicketRecord;
import org.springframework.stereotype.Service;

/**
 * 
 * @author rabbit
 * 
 */
@Service("org.ohuyo.libra.server.jumpTicketDao")
public class JumpTicketDaoImpl extends HibernateDaoSupportEx implements
		JumpTicketDao {
	@Override
	@Resource(name = "org.ohuyo.libra.server.sessionFactory")
	public void setSessionFactoryEx(SessionFactory sessionFactory) {
		super.setSessionFactoryEx(sessionFactory);
	}

	public void saveJumpTicketRecord(JumpTicketRecord jtr) {
		this.getHibernateTemplate().save(jtr);
	}

	public JumpTicketRecord getJumpTicketRecord(long jumpTicket) {
		return (JumpTicketRecord) this.getHibernateTemplate().get(
				JumpTicketRecord.class, jumpTicket);
	}

	public int deleteJumpTicketRecord(final long jumpTicket) {
		return this.getHibernateTemplateEx().executeUpdateBySql(
				"delete from t_jump_ticket where jump_ticket = ?", jumpTicket);
	}

	public int deleteInvalidJumpTicketRecord(final Date refDeadline) {
		return this.getHibernateTemplateEx().executeUpdateBySql(
				"delete from t_jump_ticket where expiry_time <= ?", refDeadline);
	}
}
